package com.tidc.seaquartz.job;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tidc.seaquartz.util.RabbitUtil;
import com.tidc.seaservermapper.dao.RabbitMessageLogDao;
import com.tidc.seaservermodel.config.RabbitConfig;
import com.tidc.seaservermodel.entity.RabbitMessageLog;
import com.tidc.seaservermodel.entity.UserTask;
import lombok.SneakyThrows;
import org.quartz.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020/10/5 9:56
 * @description：
 * @modified By：
 * @version:
 */
public class TaskCountDownJob extends QuartzJobBean {
    @Resource
    private RabbitMessageLogDao rabbitMessageLogDao;
    @Resource
    private RabbitUtil rabbitUtil;
    @Resource
    private ObjectMapper objectMapper;
    @SneakyThrows
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        Object id = jobDataMap.get("id");
        UserTask userTask = new UserTask();
        userTask.setId((Integer) id);
        RabbitMessageLog rabbitMessageLog = RabbitMessageLog.checkTaskOut(objectMapper.writeValueAsString(userTask));
        rabbitMessageLogDao.insert(rabbitMessageLog);
        rabbitUtil.sendMQ(rabbitMessageLog);
    }
}
